package com.fjnldx.mes.mapper.dataDictionary;

import com.fjnldx.mes.domain.pojo.FzyDictionaryData;
import com.fjnldx.mes.domain.pojo.FzyDictionaryDataList;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface DataDictionaryMapper {
    /**
     * 查询数据字典
     */
    @Select("<script>" +
            "SELECT * FROM fzy_dictionary_data " +
            "WHERE 1=1 " +
            "<if test='name!=null'><if test=\"name!=''\"> AND name=#{name} </if></if>" +
            "<if test='bh!=null'><if test=\"bh!=''\"> AND bh=#{bh} </if>  </if>" +
            "<if test='size!=-1'> limit ${page*size},#{size} </if>" +
            "</script>")
    List<FzyDictionaryData> queryDataDictionary(FzyDictionaryData fzyDictionaryData);

    /**
     * 查询数据字典total
     */
    @Select("<script>" +
            "SELECT count(*) FROM ( " +
            "SELECT * FROM fzy_dictionary_data " +
            "WHERE 1=1 " +
            "<if test='name!=null'><if test=\"name!=''\"> AND name=#{name} </if></if>" +
            "<if test='bh!=null'><if test=\"bh!=''\"> AND bh=#{bh} </if>  </if>" +
            ") a " +
            "</script>")
    int queryDataDictionaryTotal(FzyDictionaryData fzyDictionaryData);

    /**
     * 查询数据字典列表
     */
    @Select("<script>" +
            "SELECT * FROM fzy_dictionary_data_list " +
            "WHERE dic_bh=#{dic_bh} " +
            "<if test=\"key_name!=null and key_name!='' \"> AND key_name=#{key_name} </if>" +
            "<if test=\"key_value!=null and key_value!='' \"> AND key_value=#{key_value} </if>" +
            "<if test='size!=-1'> limit ${page*size},#{size} </if>" +
            "</script>")
    List<FzyDictionaryDataList> queryDataDictionaryList(FzyDictionaryDataList fzyDictionaryDataList);

    /**
     * 查询数据字典列表total
     */
    @Select("<script>" +
            "SELECT count(*) FROM ( " +
            "SELECT * FROM fzy_dictionary_data_list " +
            "WHERE dic_bh=#{dic_bh} " +
            "<if test=\"key_name!=null and key_name!='' \"> AND key_name=#{key_name} </if>" +
            "<if test=\"key_value!=null and key_value!='' \"> AND key_value=#{key_value} </if>" +
            ") a " +
            "</script>")
    int queryDataDictionaryListTotal(FzyDictionaryDataList fzyDictionaryDataList);

    /*
     * 新增数据字典
     */
    @Insert("insert into fzy_dictionary_data(name,bh,dec) values(#{name},#{bh},#{dec}) ")
    int insertDataDic(FzyDictionaryData fzyDictionaryData);

    /*
     * 新增数据字典成员列表
     */
    @Insert("insert into fzy_dictionary_data_list(key_name,key_value,dic_bh) values(#{key_name},#{key_value},#{dic_bh}) ")
    int insertDataDicList(FzyDictionaryDataList fzyDictionaryDataList);

    /**
     * 删除数据字典
     */
    @Delete("<script>" +
            "DELETE FROM fzy_dictionary_data WHERE id In" +
            "<foreach collection='array' item='item' index='index' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    int deleteDataDic(String[] array);

    /**
     * 删除数据字典成员列表
     */
    @Delete("<script>" +
            "DELETE FROM fzy_dictionary_data_list WHERE id In" +
            "<foreach collection='array' item='item' index='index' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    int deleteDataDicList(String[] array);
    /**
     * 更新数据字典
     */
    @Update("<script> " +
            "update fzy_dictionary_data " +
            "<trim prefix='set' suffixOverrides=','>" +
            "<if test='name!=null'> name=#{name}, </if> " +
            "<if test='bh!=null'> bh=#{bh}, </if> " +
            "<if test='dec!=null'> dec=#{dec}, </if> " +
            "</trim>" +
            "where id=#{id}" +
            "</script>")
    int updateDataDic(FzyDictionaryData fzyDictionaryData);
    /**
     * 更新数据字典成员列表
     */
    @Update("<script> " +
            "update fzy_dictionary_data_list " +
            "<trim prefix='set' suffixOverrides=','>" +
            "<if test='key_name!=null'> key_name=#{key_name}, </if> " +
            "<if test='key_value!=null'> key_value=#{key_value}, </if> " +
            "</trim>" +
            "where id=#{id} AND dic_bh=#{dic_bh} " +
            "</script>")
    int updateDataDicList(FzyDictionaryDataList fzyDictionaryDataList);
}
